//
//  Mallet.m
//  LearningCocos
//
//  Created by abyssos on 2014. 3. 3..
//  Copyright (c) 2014년 ainhan. All rights reserved.
//

#import "Mallet.h"

@implementation Mallet

@synthesize malletAnim;

- (void)dealloc {
    [malletAnim release];
    [super dealloc];
}

- (void)changeState:(CharacterStates)newState {
    if(newState == kStateSpawning) {
        malletAnim.restoreOriginalFrame = NO;
        id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:malletAnim]];
        [self runAction:action];
    } else {
        [self setVisible:NO];
        [self removeFromParentAndCleanup:YES];
    }
}

- (void)updateStateWithDeltaTime:(ccTime)deltaTime andListOfGameObjects:(CCArray *)listOfGameObjects {
    float groundHeight = screenSize.height * 0.0065f;
    if([self position].y > groundHeight)
        [self setPosition:ccp([self position].x, [self position].y - 0.5f)];
}

- (void)initAnimations {
    [self setMalletAnim:[self loadPlistForAnimationWithName:@"malletAnim" andClassName:NSStringFromClass([self class])]];
}

- (id)init {
    if((self = [super init])) {
        screenSize = [CCDirector sharedDirector].winSize;
        gameObjectType = kPowerUpTypeMallet;
        [self initAnimations];
        [self changeState:kStateSpawning];
    }
    
    return self;
}

@end
